#include "weeklytimertest.h"
#include <QDateTime>

WeeklyTimerTest::WeeklyTimerTest()
{
}

bool WeeklyTimerTest::paramDayIsInThePast()
{
    QDateTime* dt = new QDateTime(QDateTime::currentDateTime());
    *dt = dt->addDays(-1);
    int hour = dt->time().hour() + 1;
    int minute = 0;

    QDateTime* expected = new QDateTime(*dt);
    expected->setTime(QTime(hour, minute, 0, 0));
    *expected = expected->addDays(7);

    QWeeklyTimer* timer = new QWeeklyTimer((Qt::DayOfWeek) dt->date().dayOfWeek(), hour, minute);
    timer->start();

    QDateTime* calculated = timer->nextSchedule();

    if (*calculated == *expected)
        return true;
    else
        return false;
}

bool WeeklyTimerTest::paramDayIsTodayInThePast()
{
    QDateTime* dt = new QDateTime(QDateTime::currentDateTime());
    int hour = dt->time().hour() - 1;
    int minute = 0;

    QDateTime* expected = new QDateTime(*dt);
    expected->setTime(QTime(hour, minute, 0, 0));
    *expected = expected->addDays(7);

    QWeeklyTimer* timer = new QWeeklyTimer((Qt::DayOfWeek) dt->date().dayOfWeek(), hour, minute);
    timer->start();

    QDateTime* calculated = timer->nextSchedule();

    if (*calculated == *expected)
        return true;
    else
        return false;
}

bool WeeklyTimerTest::paramDayIsTodayInTheFuture()
{
    QDateTime* dt = new QDateTime(QDateTime::currentDateTime());
    int hour = dt->time().hour() + 1;
    int minute = 0;

    QDateTime* expected = new QDateTime(*dt);
    expected->setTime(QTime(hour, minute, 0, 0));

    QWeeklyTimer* timer = new QWeeklyTimer((Qt::DayOfWeek) dt->date().dayOfWeek(), hour, minute);
    timer->start();

    QDateTime* calculated = timer->nextSchedule();

    if (*calculated == *expected)
        return true;
    else
        return false;
}

bool WeeklyTimerTest::paramDayIsInTheFuture()
{
    QDateTime* dt = new QDateTime(QDateTime::currentDateTime().addDays(1));
    int hour = dt->time().hour();
    int minute = 0;

    QDateTime* expected = new QDateTime(*dt);
    expected->setTime(QTime(hour, minute, 0, 0));

    QWeeklyTimer* timer = new QWeeklyTimer((Qt::DayOfWeek) dt->date().dayOfWeek(), hour, minute);
    timer->start();

    QDateTime* calculated = timer->nextSchedule();

    if (*calculated == *expected)
        return true;
    else
        return false;
}
